//
//  PushDM.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/7/10.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "PushDM.h"
#import "UserModal.h"
#import "StringTool.h"
#import "Connect.h"


@implementation PushDM


+(void)updataPushToken:(NSString*)token{
    
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
       
        
        NSString *pushToken = token;
        
        pushToken = [pushToken stringByReplacingOccurrencesOfString:@" " withString:@""];
        pushToken = [pushToken stringByReplacingOccurrencesOfString:@"<" withString:@""];
        pushToken = [pushToken stringByReplacingOccurrencesOfString:@">" withString:@""];
        
        NSString *userCode = [UserModal shareUserModel].userCode;
        
        [[self class] setPushToken:pushToken];
        
        if(![StringTool isBlankString:userCode]){
            
            NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:userCode,@"userName",pushToken,@"deviceToken",nil];
            
            NSString *url = [NSString stringWithFormat:@"http://%@:8090/wgf-app-im/user/token",SERVER_IP];
            
            
            [Connect doPostOutCaCheWithUrl:url withParamDic:dic];
        }
    });
}




+(NSString*)getPushToken{

    NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"pushToken"];
    return   str==nil?@"":str;
}


+(void)setPushToken:(NSString*)token{
    
    [[NSUserDefaults standardUserDefaults]setObject:token forKey:@"pushToken"];
    [[NSUserDefaults standardUserDefaults]synchronize];

}



//fffffffffffffffffffffffffffffffff

+(NSDictionary*)getPushMessageRecent{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSDictionary *msgDic = [defaults dictionaryForKey:@"pushMsgDic"];
    return msgDic;
}

+(void)setPushMessageRecent:(NSDictionary*)msgDic{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:msgDic forKey:@"pushMsgDic"];
    [[NSUserDefaults standardUserDefaults]synchronize];
}


+(Boolean)pushMsgUserAble{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    Boolean fromB = [defaults boolForKey:@"comeBackGroud"];
    return fromB;
}

+(void)setPushMsgUserAble:(Boolean)comeB{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setBool:comeB forKey:@"comeBackGroud"];
    [[NSUserDefaults standardUserDefaults]synchronize];
}

///////////////////////////////


@end
